package cn.maihe.elg.operation.model.enums;

import java.util.Arrays;

/**
 * @Description 保函类型
 * @Author WJH
 * @Date 2021/03/25
 */
public enum GuaranteeType {

    GUARANTEE(0, "担保公司保函"),
    BANK_DIRECT(1, "银行直开式保函"),
    BANK_SPLIT(2, "银行分离式保函"),
    INSURANCE(3, "保险公司保函"),

    ;
    private int type;
    private String desc;

    GuaranteeType(int type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public int getType() {
        return type;
    }

    public String getTypeStr() {
        return String.valueOf(type);
    }

    public String getDesc() {
        return desc;
    }

    public static GuaranteeType resolve(int type) {
        return Arrays.stream(values()).filter(o -> o.getType() == type).findFirst().orElseThrow(() -> new RuntimeException("保函类型非法[" + type + "]"));
    }

    public static GuaranteeType resolve(String typeStr) {
        try {
            return resolve(Integer.valueOf(typeStr));
        } catch (NumberFormatException e) {
            throw new RuntimeException("保函类型非法[" + typeStr + "]", e);
        }
    }

    public static String getDescByType(String type) {
        try {
            GuaranteeType guaranteeType = resolve(type);
            return guaranteeType.getDesc();
        } catch (Exception e) {
        }
        return "";
    }

}
